fitpack_curve Derived Type

type, public :: fitpack_curve

A public type describing a curve fitter y = c(x)


Components

Type Visibility Attributes Name Initial
integer, public :: bc = OUTSIDE_NEAREST_BND
real(kind=RKIND), public, allocatable :: c(:)
real(kind=RKIND), public :: fp = zero
integer, public :: iopt = 0
integer, public, allocatable :: iwrk(:)
integer, public :: knots = 0
integer, public :: lwrk = 0
integer, public :: m = 0

The data points

integer, public :: nest = 0
integer, public :: order = 3

Spline degree

real(kind=RKIND), public :: smoothing = 1000.0_RKIND
real(kind=RKIND), public, allocatable :: sp(:)
real(kind=RKIND), public, allocatable :: t(:)
real(kind=RKIND), public, allocatable :: w(:)
real(kind=RKIND), public, allocatable :: wrk(:)
real(kind=RKIND), public, allocatable :: x(:)
real(kind=RKIND), public :: xleft

Interval boundaries

real(kind=RKIND), public :: xright

Interval boundaries

real(kind=RKIND), public, allocatable :: y(:)

Constructor

public interface fitpack_curve

  • private function new_from_points(x, y, w, ierr) result(this)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=RKIND), intent(in) :: x(:)
    real(kind=RKIND), intent(in) :: y(size(x))
    real(kind=RKIND), intent(in), optional :: w(size(x))
    integer, intent(out), optional :: ierr

    Return Value type(fitpack_curve)


Type-Bound Procedures

procedure, public :: destroy

Clean memory

  • private elemental subroutine destroy(this)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this

generic, public :: dfdx => curve_derivative, curve_derivatives

  • private function curve_derivative(this, x, order, ierr) result(ddx)

    Evaluate k-th derivative of the curve at points x Use 1st derivative if order not present

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x
    integer, intent(in), optional :: order
    integer, intent(out), optional :: ierr

    Return Value real(kind=rkind)

  • private function curve_derivatives(this, x, order, ierr) result(ddx)

    Evaluate k-th derivative of the curve at points x Use 1st derivative if order not present

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x(:)
    integer, intent(in), optional :: order
    integer, intent(out), optional :: ierr

    Return Value real(kind=RKIND), dimension(size(x))

generic, public :: eval => curve_eval_one, curve_eval_many

  • private function curve_eval_one(this, x, ierr) result(y)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x
    integer, intent(out), optional :: ierr

    Return Value real(kind=rkind)

  • private function curve_eval_many(this, x, ierr) result(y)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x(:)
    integer, intent(out), optional :: ierr

    Return Value real(kind=RKIND), (size(x))

procedure, public :: fit => curve_fit_automatic_knots

Generate/update fitting curve, with optional smoothing

  • private function curve_fit_automatic_knots(this, smoothing) result(ierr)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in), optional :: smoothing

    Return Value integer

procedure, public :: interpolate => interpolating_curve

  • private function interpolating_curve(this) result(ierr)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this

    Return Value integer

procedure, public, non_overridable :: mse => curve_error

  • private elemental function curve_error(this)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(in) :: this

    Return Value real(kind=rkind)

procedure, public :: new_fit

Generate new fit

  • private function new_fit(this, x, y, w, smoothing)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x(:)
    real(kind=RKIND), intent(in) :: y(size(x))
    real(kind=RKIND), intent(in), optional :: w(size(x))
    real(kind=RKIND), intent(in), optional :: smoothing

    Return Value integer

procedure, public :: new_points

Set new points

  • private subroutine new_points(this, x, y, w)

    Arguments

    Type IntentOptional Attributes Name
    class(fitpack_curve), intent(inout) :: this
    real(kind=RKIND), intent(in) :: x(:)
    real(kind=RKIND), intent(in) :: y(size(x))
    real(kind=RKIND), intent(in), optional :: w(size(x))

Source Code

    type :: fitpack_curve

        !> The data points
        integer :: m = 0
        real(RKIND), allocatable :: x(:),y(:)

        !> Spline degree
        integer :: order = 3

        !> Interval boundaries
        real(RKIND) :: xleft,xright

        ! Node weights
        real(RKIND), allocatable :: sp(:),w(:)

        ! Estimated and actual number of knots and their allocations
        integer                  :: nest  = 0
        integer                  :: lwrk  = 0
        integer, allocatable     :: iwrk(:)
        real(RKIND), allocatable :: wrk(:)

        ! Curve fit smoothing parameter (fit vs. points MSE)
        real(RKIND) :: smoothing = 1000.0_RKIND

        ! Actual curve MSE
        real(RKIND) :: fp = zero

        ! Curve extrapolation behavior
        integer     :: bc = OUTSIDE_NEAREST_BND

        ! Knots
        integer     :: knots = 0
        real(RKIND), allocatable :: t(:)  ! Knot location

        ! Spline coefficients [knots-order-1]
        real(RKIND), allocatable :: c(:)

        ! Runtime flag
        integer :: iopt = 0

        contains

           !> Clean memory
           procedure :: destroy

           !> Set new points
           procedure :: new_points

           !> Generate new fit
           procedure :: new_fit

           !> Generate/update fitting curve, with optional smoothing
           procedure :: fit         => curve_fit_automatic_knots
           procedure :: interpolate => interpolating_curve

           !> Evaluate curve at given coordinates
           procedure, private :: curve_eval_one
           procedure, private :: curve_eval_many
           generic :: eval => curve_eval_one,curve_eval_many

           !> Evaluate derivative at given coordinates
           procedure, private :: curve_derivative
           procedure, private :: curve_derivatives
           generic   :: dfdx => curve_derivative,curve_derivatives

           !> Properties: MSE
           procedure, non_overridable :: mse => curve_error

    end type fitpack_curve